package com.sgq.vue.controller.picture;

import com.sgq.vue.entity.picture.Plate;
import com.sgq.vue.result.Result;
import com.sgq.vue.service.picture.PlateService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 83778
 * @date: 2024-01-04 19:00
 * @desc:
 */
@Api(tags = "图片分区")
@RestController
@RequestMapping("/api/picture/plate")
public class PlateController {

    @Autowired
    private PlateService plateService;

    @PostMapping("/add")
    public Result add(@RequestBody Plate plate){
        plate.setTotal(0);
        boolean save = plateService.save(plate);
        return Result.ok(save);
    }

    @PutMapping("/edit")
    public Result edit(@RequestBody Plate plate){
        boolean update = plateService.updateById(plate);
        return Result.ok(update);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        boolean b = plateService.removeById(id);
        return Result.ok(b);
    }

    @GetMapping("/list")
    public Result list(){
        List<Plate> list = plateService.list();
        return Result.ok(list);
    }

    @GetMapping("/getPlateIdByName/{plateName}")
    public Result findPlateIdByName(@PathVariable("plateName")String plateName){
        Long plateId = plateService.findPlateIdByName(plateName);
        return Result.ok(plateId);
    }

}
